<template>
  <div>
    <div style="padding: 10px 10px 0px 0px; height: 40%; overflow: auto;">
      <el-form :label-position="labelPosition" label-width="100px">
        <el-form-item v-for="(item, index) in alldata" :style="{ 'display': item.isShow ? 'block' : 'none' }" :key="index" :label="item.title">
          <el-date-picker :id="'input_' + item.id" type="date" placeholder="选择日期" v-model="item.data" v-if="item.type === 'date'" style="width: 100%;"></el-date-picker>
          <el-col v-else-if="item.type === 'ref'">
            <el-input :id="'input_' + item.id" v-model="item.data">
              <el-button slot="append" icon="el-icon-search" @click="clickTest(item.id, item.viewid , item.refkey, index)"></el-button>
            </el-input>
          </el-col>
          <el-input :id="'input_' + item.id" v-model="item.data" v-else></el-input>
        </el-form-item>
      </el-form>
    </div>
    <el-button type="primary" @click="onSubmit" style="position:absolute;height: 12%; width: 100%; bottom: 0;">搜索</el-button>
  </div>
</template>
<script>

export default {
  props: ['alldata', 'clickmodel'],
  data () {
    return {
      labelPosition: 'right'
    }
  },
  mounted () {
    //console.log(this.alldata)
  },
  methods: {
    clickTest (id, viewid ,ref, index) {
      let itemdoc = document.getElementById('input_' + id)
      let itemrefdoc = document.getElementById('input_' + ref)
      this.$emit('update:clickmodel', { item: itemdoc, ref: itemrefdoc })
      let clickedItem = this.alldata[index]
      // document.getElementById('input_' + id).value = '测试'
      this.$router.push({
        name: 'ref',
        params: {
          bo: id,
          tobo: null,
          field: 'id',
          fieldref: 'sname',
          viewid: viewid,
          conditionVal: '',
          conditionValHidden: 'sname:in:' + itemdoc.value + ';',
          classname: null,
          params: null
        }
      })
    },
    onSubmit () {
      let data = {}
      for (let i = 0; i < this.alldata.length; i++) {
        let input = document.getElementById('input_' + this.alldata[i]['id'])
        data[this.alldata[i]['id']] = input.value
      }
      this.$emit('show-condition', data)
    }
  }
}
</script>
